home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17490 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: mail2news.demon.co.uk!txwang
  2. From: Wang TianXing <gztxwang@public1.guangzhou.gd.cn>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: int::~int()
  5. Date: Tue, 16 Apr 1996 01:00:25 GMT
  6. Message-ID: <199604160100.KAA06143@public1.guangzhou.gd.cn>
  7. X-NNTP-Posting-Host: txwang
  8. X-Newsreader: Forte Free Agent 1.0.82
  9. X-Mail2News-Path: public1.guangzhou.gd.cn!txwang
  10.  
  11. On Sun, 14 Apr 1996 13:49:59 +0900, Xu Yifeng <jafd@public.sta.net.cn>
  12. wrote:
  13.  
  14. | Hi everybody,
  15.  
  16. | can your compiler compile following program?
  17.  
  18. | //------------------------
  19. | void main()
  20. | {
  21. |      int i = 0;
  22.  
  23. |      i.int::~int();
  24. | }
  25. | //------------------------
  26.  
  27. | is it a legal C++ program?
  28.  
  29. Though many guys had said it is a legal one, I don't think it's a
  30. meaningful one.  The Sep, 95 draft Standard says in 12.4:
  31.  
  32. 12 Invocation  of  destructors  is  subject to the usual rules for
  33.    member functions (_class.mfct_), e.g., an object of the
  34.    appropriate  type  is required  (except  invoking  delete  on a
  35.    null pointer has no effect). Once a destructor is invoked for an
  36.    object,  the  object  no  longer exists;  the behavior is
  37.    undefined if the destructor is invoked for an object whose
  38.    lifetime has  ended  (_basic.life_).   [Example:  if  the
  39.    destructor  for  an  automatic  object  is explicitly invoked,
  40.    and the block is subsequently left in a manner that  would
  41.    ordinarily invoke implicit destruction of the object, the
  42.    behavior is undefined.  ]
  43.  
  44. The [Example:...], though it isn't part of the standard, says
  45. something directly related to your program.
  46.  
  47. Although there're some differences between "well-formed program" and
  48. "undefined behavior", I don't think it's a bad idea that a compiler
  49. rejects this sort of code, as it will surely cause undefined
  50. behaviors.
  51.  
  52. The plain old Borland C++ 3.1 compiles
  53.  
  54.     int i = 0;
  55.     (&i)->int::~int();
  56.  
  57. just fine.  And that's the "Standard" way(via pointer) to explicitly
  58. call a destructor.
  59.  
  60.  
  61. ---
  62. Wang TianXing
  63.  
  64.  
  65.